/**
 * 
 */
package com.mbengue.corp.apr.ra.core;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author MMB11447
 *
 */
@Entity
@Table
@NamedNativeQuery(name = "auteursParNomOuPrenom", query = "select * from membre aut where aut.nom=? or aut.prenom=?", resultClass = Membre.class)
public class Membre implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(nullable=false, unique=true, length=255)
	private String email;
	
	@Column(nullable=false, unique=false, length=64)
	private String nom;
	
	@Column(nullable=false, unique=false, length=128)
	private String prenom;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false, unique=false, length=16)
	private Date dateDeNaissance;
	
	@Column(nullable=false, unique=false, length=32)
	private String motDePasse;
	
	@Column(nullable=true, unique=true, length=16)
	private String telephone;
	
	@PrimaryKeyJoinColumn
	private Adresse adresse;
	
	@Column(nullable=true, unique=false, length=2)
	private String role;

	/**
	 * @return the nom
	 */
	public String getNom() {
		return nom;
	}

	/**
	 * @param nom the nom to set
	 */
	public void setNom(String nom) {
		this.nom = nom;
	}

	/**
	 * @return the prenom
	 */
	public String getPrenom() {
		return prenom;
	}

	/**
	 * @param prenom the prenom to set
	 */
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
	
	public String getBirthDay() {
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		return sdf.format(dateDeNaissance);
	}

	/**
	 * @return the dateDeNaissance
	 */
	public Date getDateDeNaissance() {
		return dateDeNaissance;
	}

	/**
	 * @param dateDeNaissance the dateDeNaissance to set
	 */
	public void setDateDeNaissance(Date dateDeNaissance) {
		this.dateDeNaissance = dateDeNaissance;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the motDePasse
	 */
	public String getMotDePasse() {
		return motDePasse;
	}

	/**
	 * @param motDePasse the motDePasse to set
	 */
	public void setMotDePasse(String motDePasse) {
		this.motDePasse = motDePasse;
	}

	/**
	 * @return the telephone
	 */
	public String getTelephone() {
		return telephone;
	}

	/**
	 * @param telephone the telephone to set
	 */
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	/**
	 * @return the adresse
	 */
	public Adresse getAdresse() {
		return adresse;
	}

	/**
	 * @param adresse the adresse to set
	 */
	public void setAdresse(Adresse adresse) {
		this.adresse = adresse;
	}

	/**
	 * @return the role
	 */
	public String getRole() {
		return role;
	}

	/**
	 * @param role the role to set
	 */
	public void setRole(String role) {
		this.role = role;
	}

	public String getNoms() {
		return nom.toUpperCase() + " " + prenom;
	}

	public Membre(String nom, String prenom, String email, Date dateDeNaissance, String motDePasse, String telephone, Adresse adresse, String role) {
		super();
		this.nom = nom;
		this.prenom = prenom;
		this.email = email;
		this.dateDeNaissance = dateDeNaissance;
		this.motDePasse = motDePasse;
		this.telephone = telephone;
		this.adresse = adresse;
		this.role = role;
	}
	
	public Membre() {
	}

}
